//
//  MineDataTool.m
//  Traveling
//
//  Created by 曹秀云 on 15/6/4.
//  Copyright (c) 2015年 长沙市岳麓区立早网络科技有限公司. All rights reserved.
//

#import "MineDataTool.h"

@implementation MineDataTool


+(void)registerWithParams:(NSDictionary *)params success:(void (^)(RegisterResult *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionaryWithDictionary:params];
    [param setObject:kAppValue forKey:kAppkey];
    [self postWithUrl:[NSString stringWithFormat:@"%@api/v2/join.json",BASE_URL] param:param resultClass:[RegisterResult class] success:success failure:failure];
}

+(void)loginWithUserName:(NSString *)username password:(NSString *)password loginType:(NSInteger)loginType success:(void (^)(RegisterResult *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionary];
    [param setObject:kAppValue forKey:kAppkey];
    [param setObject:username forKey:@"user_name"];
    [param setObject:password forKey:@"password"];
    NSString *url = @"";
    if (loginType == companyIdentityType) {
        //商户
        url = [NSString stringWithFormat:@"%@api/v2/seller_login.json",BASE_URL];
    }else{
        //个人
        url = [NSString stringWithFormat:@"%@api/v2/login.json",BASE_URL];
    }
    
    [self postWithUrl:url param:param resultClass:[RegisterResult class] success:success failure:failure];
}

+(void) getMyTripOrders:(NSString *)user_id maxId:(NSInteger)maxId success:(void (^)(TripOrderRes *result))success failure:(void (^)(NSError *error))failure{

    NSMutableDictionary *param =[NSMutableDictionary dictionary];
    [param setObject:kAppValue forKey:kAppkey];
    [param setObject:user_id forKey:@"user_id"];
    [param setObject:[NSNumber numberWithInteger:maxId] forKey:@"max_id"];
    
    [self postWithUrl:[NSString stringWithFormat:@"%@journey/user_plan_list.json",BASE_URL] param:param resultClass:[TripOrderRes class] success:success failure:failure];
    
}

+(void)saveOrderInfo:(NSMutableDictionary *)params success:(void (^)(OrderEditRes *))success failure:(void (^)(NSError *))failure{
    [params setObject:kAppValue forKey:kAppkey];
    [self postWithUrl:[NSString stringWithFormat:@"%@order/order_save.json",BASE_URL] param:params resultClass:[OrderEditRes class] success:success failure:failure];
}

+(void)getOrderInfo:(NSInteger)order_type max_id:(NSInteger)max_id success:(void (^)(OrderItemRes *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *params =[NSMutableDictionary dictionary];
    [params setObject:kAppValue forKey:kAppkey];
    NSString *uid =  [DefaultsHelper stringForKey:kUserId];
    [params setObject:uid forKey:@"user_id"];
    [params setObject:[NSNumber numberWithInteger:max_id] forKey:@"max_id"];
    [params setObject:[NSNumber numberWithInteger:order_type] forKey:@"order_type"];
    [self postWithUrl:[NSString stringWithFormat:@"%@order/order_list.json",BASE_URL] param:params resultClass:[OrderItemRes class] success:success failure:failure];
}

+(void)getOrderDetailInfo:(NSString *)order_sn success:(void (^)(OrderDetailRes *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *params =[NSMutableDictionary dictionary];
    [params setObject:kAppValue forKey:kAppkey];
    NSString *uid =  [DefaultsHelper stringForKey:kUserId];
    [params setObject:uid forKey:@"user_id"];
    [params setObject:order_sn forKey:@"order_sn"];
        [self postWithUrl:[NSString stringWithFormat:@"%@order/order_info.json",BASE_URL] param:params resultClass:[OrderDetailRes class] success:success failure:failure];
}

+(void) getTripDetailInfoWithPlanId:(NSString *)plan_id success:(void (^)(TripDetailResult *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionary];
    [param setObject:kAppValue forKey:kAppkey];
    [param setObject:plan_id forKey:@"plan_id"];
    [self postWithUrl:[NSString stringWithFormat:@"%@journey/info.json",BASE_URL] param:param resultClass:[TripDetailResult class] success:success failure:failure];
}

+(void)createTripOrderUserId:(NSString *)user_id json_plan:(NSString *)json_plan  success:(void (^)(BaseResponse *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionary];
    [param setObject:kAppValue forKey:kAppkey];
    [param setObject:user_id forKey:kUserId];
    [param setObject:json_plan forKey:@"json_plan"];
    [self postWithUrl:[NSString stringWithFormat:@"%@journey/save.json",BASE_URL] param:param resultClass:[BaseResponse class] success:success failure:failure];
}

+(void) getTripProjectListSinceId:(NSString *)since_id maxId:(NSInteger)maxId type:(NSInteger) type success:(void (^)(TripPorjectListResult *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionary];
    [param setObject:since_id forKey:since_id];
    [param setObject:[NSNumber numberWithInteger:maxId] forKey:@"max_id"];
    if (type) {
        [self postWithUrl:[NSString stringWithFormat:@"%@journey/hotel_list.json",BASE_URL] param:param resultClass:[TripPorjectListResult class] success:success failure:failure];
    }else{
        [self postWithUrl:[NSString stringWithFormat:@"%@journey/scenic_list.json",BASE_URL] param:param resultClass:[TripPorjectListResult class] success:success failure:failure];
    }
}

+(void)getSignOrderInfo:(NSString *)paydata success:(void (^)(SignPayRes *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionary];
    [param setObject:kAppValue forKey:kAppkey];
    [param setObject:paydata forKey:@"paydata"];
    [self postWithUrl:[NSString stringWithFormat:@"%@order/order_sign.json",BASE_URL] param:param resultClass:[SignPayRes class] success:success failure:failure];
}

@end

